package leecode

func removeNthFromEndLCR(head *ListNode, n int) *ListNode {
	dummyHead := &ListNode{}
	dummyHead.Next = head
	temp := dummyHead.Next
	cur := dummyHead.Next
	index := 0
	for cur != nil {
		cur = cur.Next
		index++
	}
	if index == 1 {
		return nil
	}
	index = index - n + 1
	if index == 1 {
		return dummyHead.Next.Next
	}
	i := 1
	for temp != nil {
		if i+1 == index {
			temp.Next = temp.Next.Next
		} else {
			temp = temp.Next
		}
		i++
	}
	return dummyHead.Next
}
